<?php
include "../include/config.php";
include "../include/db.php";

$repart = (isset($_REQUEST['repart']))? $_REQUEST['repart']:866; //866 informatica
?>

<thead>
	<tr>
		<th colspan="2" ></th>
		<?php 
		// $query2 = "SELECT id_usuario, nombre_usuario, desc_corta, R.id_rep_dep
				// FROM admin_usuarios 
				// JOIN vw_agentes A ON ( id_usuario = legajo )
				// JOIN vw_repart R ON (A.id_rep_dep = R.id_rep_dep)
				// WHERE c_estado = 1"; //usuarios
		
		// $query2 = "						
				// SELECT U.id_usuario, nombre_usuario ,R.id_rep_dep, R.desc_corta, P.id_perfil, F.desc_perfil, R.c_pertenece_grupo
				// FROM admin_usuarios U 
				// JOIN vw_agentes A ON (U.id_usuario = A.legajo)
				// JOIN vw_repart R ON (A.id_rep_dep = R.id_rep_dep)					
				// LEFT JOIN admin_usuarios_permiso_perfil P ON ( P.id_usuario = U.id_usuario AND P.pertenece_grupo = R.c_pertenece_grupo)
				// LEFT JOIN admin_perfil F ON (P.id_perfil = F.id_perfil )
				// WHERE c_estado = 1 and R.id_rep_dep = $repart					
				// GROUP BY id_rep_dep, nombre_usuario
				// ORDER BY id_rep_dep ASC"; //usuarios	

		$query2 = "	
		SELECT P.id_usuario, U.nombre_usuario, P.id_rep_dep, getNombreReparticion(P.id_rep_dep) AS desc_corta
		FROM admin_usuarios_permiso_perfil P
		JOIN admin_usuarios U ON ( P.id_usuario = U.id_usuario )
		WHERE id_rep_dep = $repart"; //usuarios

		$result2 = mysql_query($query2) or trigger_error(mysql_error());
		$CANT_USERS = mysql_num_rows($result2);

		$arr_users = Array();
		$arr_reparts = Array();
		while ($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { 
			$arr_users[] = $row2['id_usuario'];
			$arr_reparts[] = $row2['id_rep_dep'];
		?>
			<th class="celda columna col_rep_<?php echo $row2['id_rep_dep'] ?>">
				<b><?php echo $row2['nombre_usuario'] ?></b>
				<br>
				<?php echo utf8_encode($row2['desc_corta']) ?>
				<br>
				<div class='{"user":"<?php echo $row2['id_usuario'] ?>","grupo":"<?php echo $row2['c_pertenece_grupo'] ?>"}'>
					<!--b class="editable_perfil">[<?php //echo $row2['desc_perfil'] ?>]</b-->
				</div>
			</th>
		<?php  
		} 
		?>
	</tr>
</thead>
<tbody>				
	<?php 
	$query = "SELECT id_menu, descripcion FROM admin_menu WHERE id_menu_padre = 0 AND habilitado = 'S' ORDER BY orden ASC"; //menues principales
	//$query = "SELECT id_menu, descripcion FROM admin_menu WHERE id_menu_padre = 0 AND habilitado = 'S' ORDER BY orden ASC"; //menues principales
	$result = mysql_query($query) or trigger_error(mysql_error());
	while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
		$id_menu = $row['id_menu']; 	
	?>
		<tr class="fila fila_menu_<?php echo $row['id_menu'] ?>" style="background-color:#E2E4FF;">
			<td class="celda" width="100" style="color:blue;">						
				<img onclick="" class="boton_mas" name="<?php echo $row['id_menu'] ?>" style="cursor:pointer" src="images/notice-alert.png" width="15" title="" />
				<?php echo $row['descripcion'] ?>
			</td>
			<td class="celda" width="100"></td>
			<?php for($i=0; $i<$CANT_USERS; $i++){ ?> 
			<td class="celda columna col_rep_<?php echo $arr_reparts[$i]?>" >
				ve menu? <input name="" id="check_MenuPadreId_<?php echo $row['id_menu'] ?>_UserId_<?php echo $arr_users[$i]?>" class="check" onclick="habilitar_menu_para(<?php echo $arr_users[$i]?>, <?php echo $row['id_menu'] ?>, this)" type="checkbox" />
			</td> 
			<?php } ?>
		</tr>
	
	<?php
		
		$query5 = "SELECT id_menu, descripcion FROM admin_menu WHERE id_menu_padre = {$id_menu} AND habilitado = 'S' ORDER BY orden ASC";
		$result5 = mysql_query($query5) or trigger_error(mysql_error());
		while ($row5 = mysql_fetch_array($result5, MYSQL_ASSOC)) { 				
			
	?>
			<tr class="fila fila_menu_<?php echo $row5['id_menu'] ?>">
				<td class="celda" width="100" style=""></td>
				<td class="celda submenu" width="100" id="submenuid_<?php echo $row5['id_menu'] ?>"><?php echo $row5['descripcion'] ?></td>
				<?php for($i=0; $i<$CANT_USERS; $i++){ ?> 
				<td class="celda columna col_rep_<?php echo $arr_reparts[$i]?>" >
					<input name="" id="check_MenuId_<?php echo $row5['id_menu'] ?>_UserId_<?php echo $arr_users[$i]?>" class="check" onclick="habilitar_permiso_para(<?php echo $arr_users[$i]?>, <?php echo $row['id_menu'] ?>, <?php echo $row5['id_menu'] ?>, this)" type="checkbox" />
				</td> 
				<?php } ?>
			</tr>
	<?php
		}
	} 
	?>			
</tbody>
	
